package com.ruantu.clothing.service.wxpandian;

import com.ruantu.clothing.dao.wxpandian.WXPandianDao;
import com.ruantu.clothing.entity.wxpandian.*;
import com.ruantu.clothing.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class WXPandianServiceImpl implements WXPandianService {
    @Autowired
    private WXPandianDao wxPandianDao;

    public WXPandianDao getWxPandianDao() {
        return wxPandianDao;
    }

    public void setWxPandianDao(WXPandianDao wxPandianDao) {
        this.wxPandianDao = wxPandianDao;
    }
    //通过编号查询商品详情
    public ReseltMap_A selectPdByCode(String product_code,String jg_id){
        return wxPandianDao.selectPdByCode(product_code,jg_id);
    }

    /**
     * 获取最新盘点
     * @return
     */
    public Pandian selectNewPandian(String jg_id){return wxPandianDao.selectNewPandian(jg_id);}

    /**
     * 获取根据产品条码获取storeID
     * @param product_code 产品条码
     * @return 最新盘点
     */

    public String selectStoreIdByCode(String product_code,String jg_id){return wxPandianDao.selectStoreIdByCode(product_code,jg_id);}

    /**
     * 新增盘点子表记录
     * @param store_id storeID
     * @param shuliang  盘点后数量
     * @param pandianren 盘点人
     * @param pandian_id 盘点ID
     * @param yk    盈亏
     */
    //void insertJLtoPdChild (String store_id,Integer shuliang,String pandianren,String pandian_id,Integer yk);
    public void insertJLtoPdChild (String store_id,Integer shuliang,Integer pandianren,String pandian_id,Integer yk){

        String pdzb_id= UUID.randomUUID().toString().replace("-", "");
        //System.out.println(pdzb_id);
        wxPandianDao.insertJLtoPdChild(pdzb_id,store_id,shuliang,pandianren,pandian_id,yk);
    }

    /**
     *查询此次（最新）盘点记录详情
     * @param selectText 条码
     * @param index 页码
     * @param size 条数
     * @return
     */
    public List<ResultMap_PDJLXQ> selsctNewPDXQ (String selectText, String jg_id,Integer index, Integer size){
        return wxPandianDao.selsctNewPDXQ(selectText,jg_id,(index-1)*size, size);
    }


    /**
     * 查询此次（最新）盘点记录数量
     * @param selectText 搜索条件
     * @return
     */
    public Integer selsctNewPDXQCount(String selectText,String jg_id,Integer size){
        int totalCount = wxPandianDao.selsctNewPDXQCount(selectText,jg_id);
        int totalPage=(totalCount-1)/size+1;
        return totalPage;
    }

    /**
     * 修改此次盘点的商品库存
     * @param update_shuliang 修改后的数量
     * @param pdzb_id   需要修改的盘点子表
     */
    public void updatePDZB_shuling(Integer update_shuliang,Integer yk,String pdzb_id){
        wxPandianDao.updatePDZB_shuling(update_shuliang,yk,pdzb_id);

    }

    /**
     * 根据款号/编号查询产品
     * @param selectText 搜索条件
     * @return
     */
    public List<PdBySelect> selectProductBys(String selectText,String jg_id,Integer index,Integer size){
        return wxPandianDao.selectProductBys(selectText,jg_id,(index-1)*size, size);
    }

    /**
     * 获取根据款号/编号查询的产品的总条数
     * @param selectText 搜索条件
     * @return 总条数
     */
    public Integer selectTotalpageByCount(String selectText,String jg_id,Integer size){
        int totalCount=wxPandianDao.getCountFselectProductBys(selectText,jg_id);
        int totalPage=(totalCount-1)/size+1;
        return totalPage;
    }

    /**
     * 盘点子表查重
     * @param store_id
     * @param pandian_id
     * @return
     */
    public ModResult selectRepetition(String store_id, String pandian_id){
        ModResult modResult=new ModResult();
        modResult.setResultCount(wxPandianDao.selectRepetitionCount(store_id,pandian_id));
        modResult.setPdzb_id(wxPandianDao.selectRepetitionPdzbID(store_id,pandian_id));
        return modResult;
    }

}
